<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<head th:include="/include/commonHeader::commonHeader('备份类型编辑')"></head>
<body>
<div class="wrapper wrapper-content">
    <div class="col-sm-12">
        <form class="form-horizontal m-t" id="exampleForm">
            <input id="bakType" name="bakType" th:value="${backupType.bakType}"  type="hidden">
            <input id="moduleFlag" name="moduleFlag" th:value="${backupType.moduleFlag}"type="hidden">
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label><font style="color:red;">*</font>备份类型：</label>
                </div>
                <div class="col-xs-8">
                    <input id="bakName" name="bakName" th:value="${backupType.bakName}" class="form-control" type="text" disabled>
                </div>
            </div>
           <!-- <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label><font style="color:red;">*</font>开始时间：</label>
                </div>
                <div class="col-xs-8">
                    <input id="startTime" name="startTime" th:value="${backupType.startTime}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label><font style="color:red;">*</font>结束时间：</label>
                </div>
                <div class="col-xs-8">
                    <input id="endTime" name="endTime" th:value="${backupType.endTime}" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label>备份人员要求：</label>
                </div>
                <div class="col-xs-8">
                    <select id="remark" name="remark" class="form-control" th:value="${backupType.remark}"></select>
                </div>
            </div>
            <div class="form-group">
                <div class="text-center">
                    <button id="btn_save" onclick="save()" type="button" class="btn btn-primary">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
    <script src="/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
    <script src="/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
<!-- 自定义js -->
	<script th:inline="javascript">
        var prefix = "/backupType";
        var isReadonly = "[[${isReadonly}]]";//页面是否只能查看

        $(function(){
            if(isReadonly === "1"){
                //  readonlyInput();
            }else{
                initValidator();
                //initDatePlugin();
            }
        });

        //禁用所有输入框
        function readonlyInput(){
            $("#exampleForm").find("input,textarea,checkbox,radio").attr("readonly",true);
            $("#exampleForm").find("select").prop("disabled",true);
            $("#btn_save").hide();//隐藏操作按钮
        }

        //下拉框初始化
        $(function () {
            //初始化下列框
            select2InitForData("#remark", "/select2/getCrewNumberType.do?moduleFlag="+$("#moduleFlag").val(),[[${backupType.remark}]], null, false, null);      //组搭配标准C3026
        });

        //保存
        function save(){
            /*$("#exampleForm").data('bootstrapValidator').validate();//触发一次所有的验证
            if(!$("#exampleForm").data('bootstrapValidator').isValid()){//判断验证是否已经通过
                return;
            }*/

            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/update.do",
                data : $('#exampleForm').serialize(),
                error : function(request) {
                    toastr.error("Connection error");
                },
                success : function(data) {
                    if (data.code == 0) {
                        parent.toastr.success("操作成功");
                        parent.reload();
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);
                    } else {
                        toastr.warning(data.msg)
                    }
                }
            });
        }

        //初始化验证规则
        function initValidator(){
           $('#exampleForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                startTime: {
                    message: 'The value is not valid',
                    validators: {
                        notEmpty: {
                            message: '开始时间不能为空'
                        }
                    }
                },
                endTime: {
                    message: 'The value is not valid',
                    validators: {
                        notEmpty: {
                            message: '结束时间不能为空'
                        }
                    }
                }
            }
        });
        }

        //初始化日期控件
        function initDatePlugin(){
            $("#startTime").datetimepicker({
                minView: "hour",
                language:  'zh-CN',
                format: 'yyyy-mm-dd hh:ii',
                autoclose: true,
                todayBtn: true,
            }).on('changeDate show', function (ev) {
                $("#endTime").datetimepicker('setStartDate',$("#startTime").val());
                $('#exampleForm').data('bootstrapValidator')
                    .updateStatus('startTime', 'NOT_VALIDATED', null)
                    .validateField('startTime');
            });

            $("#endTime").datetimepicker({
                minView: "hour",
                language:  'zh-CN',
                format: 'yyyy-mm-dd hh:ii',
                autoclose: true,
                todayBtn: true,
            }).on('changeDate show', function (ev) {
                $("#startTime").datetimepicker('setEndDate',$("#endTime").val());
                $('#exampleForm').data('bootstrapValidator')
                    .updateStatus('endTime', 'NOT_VALIDATED', null)
                    .validateField('endTime');
            });
        }
	</script>
</body>
</html>
